package com.killer.designcontrols.utils;

import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;

/**
 * Created by killer on 2016/5/10.
 */
public class AnimUtil {
    public static int animCount = 0;//记录当前执行的动画数量
    public static void closeMenu(RelativeLayout rl,int startOffset){
        //关闭之后设置为不可用
        for (int i= 0;i<rl.getChildCount();i++){
            rl.getChildAt(i).setEnabled(false);
        }

        RotateAnimation animation = new RotateAnimation(0,-180,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,1);
        animation.setDuration(500);//动画时间
        animation.setFillAfter(true);//动画结束后保持状态
        animation.setStartOffset(startOffset);//延迟效果

        animation.setAnimationListener(new MyAnimationListener());
        rl.startAnimation(animation);
    }
    public static void showMenu(RelativeLayout rl,int startOffset){
        //打开之后设置为可用
        for (int i= 0;i<rl.getChildCount();i++){
            rl.getChildAt(i).setEnabled(true);
        }
        RotateAnimation animation = new RotateAnimation(-180,0,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,1);
        animation.setDuration(500);//动画时间
        animation.setFillAfter(true);//动画结束后保持状态
        animation.setStartOffset(startOffset);
        animation.setAnimationListener(new MyAnimationListener());
        rl.startAnimation(animation);
    }
    static class  MyAnimationListener implements Animation.AnimationListener{

        @Override
        public void onAnimationStart(Animation animation) {
            animCount++;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            animCount--;
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    }
}
